function TrTableView(controller, div, accountManager, curManager, categoryManager, tagManager, config) {

	var self = this;
	this.pagerDiv = 'trPager';
	var pager = new Pager(this.pagerDiv);
	var selectedId = null;

	var onHeaderSort = function(field, oldSorting) {
		var dir = SortDir.ASC;
		if(oldSorting.field != null && oldSorting.field === field && !oldSorting.isDesc()) {
			dir = SortDir.DESC;
		}
		$(self).trigger('sort-change', { sorting: new Sorting(field, dir) });
	};

	this.update = function(transactions, total, page, pageSize, sorting) {
		var totalBalance = {};
		var sortableHeaders = {};
		createSortableHeader(sortableHeaders, 'date', div, 'Дата', sorting);
		createSortableHeader(sortableHeaders, 'category', div, 'Категория', sorting);
		createSortableHeader(sortableHeaders, 'desc', div, 'Описание', sorting);
		createSortableHeader(sortableHeaders, 'srcAccount', div, 'Счет', sorting);
		createSortableHeader(sortableHeaders, 'srcSum', div, 'Сумма', sorting);
		createSortableHeader(sortableHeaders, 'srcCur', div, 'Валюта', sorting);
		createSortableHeader(sortableHeaders, 'dstAccount', div, 'Счет', sorting);
		createSortableHeader(sortableHeaders, 'dstSum', div, 'Сумма', sorting);
		createSortableHeader(sortableHeaders, 'dstCur', div, 'Валюта', sorting);
		var html = '<table class="data-table" align="center">' +
			'<tr class="data-table-header">' +
				'<td rowspan="2" class="data-table-cell">' + sortableHeaders['date'].html + '</td>' +
				'<td colspan="3" class="data-table-cell">Расход</td>' +
				'<td colspan="3" class="data-table-cell">Доход</td>' +
				'<td rowspan="2" class="data-table-cell">' + sortableHeaders['category'].html + '</td>' +
				'<td rowspan="2" class="data-table-cell">Теги</td>' +
				'<td rowspan="2" class="data-table-cell">' + sortableHeaders['desc'].html + '</td>' +
				'<td rowspan="2" class="data-table-cell"></td></tr>' +
			'<tr class="data-table-header">' +
				'<td class="data-table-cell">' + sortableHeaders['srcAccount'].html + '</td>' +
				'<td class="data-table-cell">' + sortableHeaders['srcSum'].html + '</td>' +
				'<td class="data-table-cell">' + sortableHeaders['srcCur'].html + '</td>' +
				'<td class="data-table-cell">' + sortableHeaders['dstAccount'].html + '</td>' +
				'<td class="data-table-cell">' + sortableHeaders['dstSum'].html + '</td>' +
				'<td class="data-table-cell">' + sortableHeaders['dstCur'].html + '</td>' +
			'</tr>';

		var trClass;
		var srcAccount, srcSum, srcCur, dstAccount, dstSum, dstCur, category;
		$.each(transactions, function(index, tr) {
			srcAccount = srcSum = srcCur = dstAccount = dstSum = dstCur = category = '';
			if(tr.dstAccId != null) {
				totalBalance[tr.dstCurId] = getNumber(totalBalance, tr.dstCurId) + tr.dstSum * tr.profit;
				dstAccount = accountManager.resolve(tr.dstAccId, 'name');
				dstSum = formatSum(tr.dstSum);
				dstCur = curManager.resolve(tr.dstCurId, 'name');
			}
			if(tr.srcAccId != null) {
				totalBalance[tr.srcCurId] = getNumber(totalBalance, tr.srcCurId) + tr.srcSum * tr.profit;
				srcAccount = accountManager.resolve(tr.srcAccId, 'name');
				srcSum = formatSum(tr.srcSum);
				srcCur = curManager.resolve(tr.srcCurId, 'name');
			}
			if(tr.categoryId != null) {
				category = categoryManager.find(tr.categoryId);
				if(category != null) {
					category = category.fullName();
				}
			}
			trClass = ["data-table-row"];
			if(selectedId === tr.id) {
				trClass.push("data-table-row-selected");
			}
			if(tr.profit > 0) {
				trClass.push("income");
			} else if(tr.profit < 0) {
				trClass.push("outcome");
			}
			html += '<tr id="' + div + 'Tr' + tr.id + '" class="' + trClass.join(' ') + '">' +
					'<td class="data-table-cell">' + formatDate(tr.date) + '</td>' +
					'<td class="data-table-cell">' + srcAccount + '</td>' +
					'<td class="data-table-cell data-table-sum-cell">' + srcSum + '</td>' +
					'<td class="data-table-cell">' + srcCur + '</td>' +
					'<td class="data-table-cell">' + dstAccount + '</td>' +
					'<td class="data-table-cell data-table-sum-cell">' + dstSum + '</td>' +
					'<td class="data-table-cell">' + dstCur + '</td>' +
					'<td class="data-table-cell">' + category + '</td>' +
					'<td class="data-table-cell">' + tr.tags.join(', ') + '</td>' +
					'<td class="data-table-cell">' + tr.desc + '</td>' +
					'<td>&nbsp;<input id="' + div + 'RemoveBtn' + tr.id + '" type="button" value="X" />&nbsp;</td>' +
				'</tr>';
		});

		var totalSums = new Array();
		var totalCurs = new Array();
		var sum;
		var style;
		for(var cur in totalBalance) {
			sum = totalBalance[cur];
			style = (sum > 0)? 'income': (sum < 0)? 'outcome': '';
			totalCurs.push('<span class="' + style + '">' + curManager.resolve(cur, 'name') + '</span>');
			totalSums.push('<span class="' + style + '">' + formatSum(sum) + '</span>');
		}
		html += '<tr class="data-table-total">' +
			'<td colspan="7" align="left" class="data-table-pager"><div id="' + this.pagerDiv + '"></div></td>' +
			'<td align="right" style="vertical-align: top">Баланс:</td>' +
			'<td align="right">' + totalSums.join('<br>') + '</td>' +
			'<td colspan="2" align="left">' + totalCurs.join('<br>') + '</td>' +
			'</tr>';
		html += '</table>';
		el(div).html(html);
		$.each(Object.keys(sortableHeaders), function(index, field) {
			el(sortableHeaders[field].id).click(function () {
				onHeaderSort(field, sorting);
			});
		});

		$.each(transactions, function(index, tr) {
			el(div + 'Tr' + tr.id).click(function() {
				self.selectRow(tr);
			});
			createSimpleButton(div + 'RemoveBtn' + tr.id, 20, 22, function() {
				Apprise('Вы уверены, что хотите удалить транзакцию', {
					buttons: {
						confirm: {
							text: 'Да',
							action: function() {
								Apprise('close');
								controller.removeTransaction(tr.id);
							}
						},
						cancel: {
							text: 'Отмена',
							action: function() {
								Apprise('close');
							}
						}
					},
					animation: 0,
					width: 500
				});

			});
		});
		pager.render(page, pageSize, Math.ceil(total / pageSize));
	};

	this.selectRow = function(tr) {
		if(selectedId !== tr.id) {
			var selectedRows = el(div).find('tr.data-table-row-selected');
			if(selectedRows.length > 0) {
				selectedRows.removeClass('data-table-row-selected');
			}
			el(div + 'Tr' + tr.id).addClass('data-table-row-selected');
			$(this).trigger('tr-selected', { item: tr });
		}
		selectedId = tr.id;
	};

	this.cleanSelection = function() {
		if(selectedId != null) {
			var selectedRows = el(div).find('tr.data-table-row-selected');
			if(selectedRows.length > 0) {
				selectedRows.removeClass('data-table-row-selected');
			}
			selectedId = null;
			$(this).trigger('tr-selected', { item: null });
		}
	};
};